package me.send.data.service.service;

import java.math.BigDecimal;

import me.send.data.service.mapper.FinanceMapper;
import me.send.data.service.pojo.Finance;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FinanceService {
    @Autowired
    private FinanceMapper financeMapper;
    
    public Finance queryFinanceReport(){
    	Finance finance=new Finance();
    	BigDecimal payOrderSum=financeMapper.queryPayOrderAmountSum();
    	BigDecimal fundSum=financeMapper.queryFundPoolConsumerSum();
    	BigDecimal frozenSum=financeMapper.queryBrokerFrozenAmountSum();
    	BigDecimal purchaseBalance=financeMapper.queryBrokerPurchaseBalanceSum();
    	BigDecimal tipBalance=financeMapper.queryBrokerTipBalanceSum();
    	BigDecimal earnPurchaseSum= financeMapper.queryBrokerEarnPurchaseAmountSum();
    	BigDecimal earnTipSum= financeMapper.queryBrokerEarnTipAmountSum();
    	BigDecimal withdrawingSum=  financeMapper.queryWithdrawingAmountSum();  	
    	BigDecimal withdrawingNotAuthSum=  financeMapper.queryWithdrawingNotAuthAmountSum();  	
    	BigDecimal withdrawSuccessSum=  financeMapper.queryWithdrawSuccessAmountSum();  	
    	BigDecimal userWalletLogSum=  financeMapper.queryUserWalletLogSum();  	
    	if(payOrderSum==null){
    		payOrderSum=new BigDecimal(0);
    	}
    	if(fundSum==null){
    		fundSum=new BigDecimal(0);
    	}
    	BigDecimal incomeSum=payOrderSum.add(fundSum);
    	
    	if(earnPurchaseSum==null){
    		earnPurchaseSum=new BigDecimal(0);
    	}
    	if(earnTipSum==null){
    		earnTipSum=new BigDecimal(0);
    	}
    	BigDecimal paySum=earnPurchaseSum.add(earnTipSum).add(userWalletLogSum);
    	
    	if(frozenSum==null){
    		frozenSum=new BigDecimal(0);
    	}
    	if(purchaseBalance==null){
    		purchaseBalance=new BigDecimal(0);
    	}
    	if(tipBalance==null){
    		tipBalance=new BigDecimal(0);
    	}
    	if(withdrawSuccessSum==null){
    		withdrawSuccessSum=new BigDecimal(0);
    	}
    	if(withdrawingSum==null){
    		withdrawingSum=new BigDecimal(0);
    	}
    	if(withdrawingNotAuthSum==null){
    		withdrawingNotAuthSum=new BigDecimal(0);
    	}
    	
    	BigDecimal brokerEarnSum=purchaseBalance.add(tipBalance).add(withdrawSuccessSum).add(withdrawingNotAuthSum).add(withdrawingSum);
    	
    	finance.setBrokerEarnPurchaseSum(earnPurchaseSum);
    	finance.setBrokerEarnTipSum(earnTipSum);
    	finance.setBrokerFrozenSum(frozenSum);
    	finance.setBrokerPurchaseBalanceSum(purchaseBalance);
    	finance.setBrokerTipBalanceSum(tipBalance);
    	finance.setFundSum(fundSum);
    	finance.setPayOrderSum(payOrderSum);
    	finance.setWithdrawingSum(withdrawingSum);
    	finance.setWithdrawNotAuthSum(withdrawingNotAuthSum);
    	finance.setWithdrawSuccessSum(withdrawSuccessSum);
    	finance.setIncomeSum(incomeSum);
    	finance.setPaySum(paySum);
    	finance.setBrokerEarnSum(brokerEarnSum);
    	
    	return finance;
    }
   
    
   
}
